<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page language="java" import="com.sinodata.bsm.common.vo.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>wmi-config-update</title>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/form.jsp"%>
	
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery-ui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/select/jquery.multiselect.min.js"></script>
	<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/select/jquery.multiselect.css" />
	<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/jqueryui/jquery-ui.css" />
	
  <script type="text/javascript">
  
  function edit(){
	 $.ajax({
		   type: "POST", 
		   url: "${pageContext.request.contextPath}/config/wmi-config!save.action", //请求的action
		   data:$("#myform").serialize(),
		   dataType: 'json',
		   success: function(data){ //结果
			   if(data == true){
			   	   var isRef = '${isRef}';
			   	   if(isRef=='null'||isRef==''){
			   	   	 	var pWin = getTopWin(window).currentWin["update-wmi-config"];
				  	 	pWin.datagrid('${isRef}');
			   	   }
				   getTopWin(window).closejBox("update-wmi-config");
			   }
			   else{
				   getTopWin(window).getMessageBox().alert("此配置已经被删除，请返回并刷新列表","提示");
			   }
		   }
	});
	  
	  
  }
  
  //修改负责人的代码
  /**
  $(function(){
	  var administrators = '${protocolParameter.administrator}';
  	  var us = administrators.split(",");
	  $.ajax({
			url : '${pageContext.request.contextPath}/config/host-config!getAllUsers.action', // 
			type : 'POST',
			dataType : "json",
			data : {},
			success : function(data) {
				$.each(data.users, function(i, index) {
					var flag = 0;
					for(var j=0;j<us.length;j++){
						if(index.userId.trim()==us[j].trim()){
							flag = flag +1;
						}
					}
					if(flag>0){
						$('#administrator').append('<option  value='+index.userId+' selected="select">' + index.userName+ '</option> ');
					}else{
						$('#administrator').append('<option  value='+index.userId+'>' + index.userName+ '</option> ');
					}
				});
				
				$('#administrator').multiselect({
					   selectedList: 2
				});
			}
		});
  });*/
  
  $(function(){
	  $.formValidator.initConfig({formid:"myform"
          ,onerror:function(msg){}
          ,onsuccess:function(){
        	  		edit();
          			return false;
          }
          });
	  $("#userName").formValidator({onshow:"请输入字符串 长度(1-32)",onfocus:"请输入字符串 长度(1-32)",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"}).inputValidator({empty:{leftempty:false,rightempty:false,emptyerror:"两边不能有空格"},onerror:"不能为空"})
	  .functionValidator({
			    fun:function(val,elem){
			    	    if(val.replace(/[^\x00-\xff]/g, "xx").length > 32){
			    	        return "长度超出最大范围";
			    	    }
			    	    return true;
				}
	  });
	  $("#pwd").formValidator({onshow:"请输入字符串 长度(1-32)",onfocus:"请输入字符串 长度(1-32)",oncorrect:""}).inputValidator({empty:{leftempty:false,rightempty:false,emptyerror:"两边不能有空格"},onerror:"不能为空"})
	  .functionValidator({
			    fun:function(val,elem){
			    	    if(val.replace(/[^\x00-\xff]/g, "xx").length > 32){
			    	        return "长度超出最大范围";
			    	    }
			    	    return true;
				}
	  });
	  $("#pwd1").formValidator({onshow:"2次密码要一致",onfocus:"2次密码要一致",oncorrect:""}).compareValidator({desid:"pwd",operateor:"=",onerror:"2次密码不一致"});
 
  });
  function closewin(){
	   getTopWin(window).closejBox("update-wmi-config");
  }

  function test(){
	  $("#testTable").css({"display":""});
	  $.ajax({
		   type: "POST", 
		   url: "${pageContext.request.contextPath}/config/config-conn!allProbe.action", //请求的action
		   data: '', //传的参数
		   dataType: 'json',
		   success: function(data){ //结果
			   var obj= document.getElementById("result");
			   obj.length=0;
			   if(data.length == 0){
				   obj.options[0]=new Option("没有正在运行的probe!");
			   }else{
				   for(var i = 0; i < data.length; i++){
					   obj.options[i]=new Option(data[i].name+"   测试中，请等待...",data[i].id);
				   }
				   var num = 0;
				   connTest(data,num);
			   }
		   }
		});
  }
  
  function connTest(probe,num){
		  $.ajax({
				type : "POST",
				url : "${pageContext.request.contextPath}/config/config-conn!connTest.action", //请求的action
				data : $("#myform").serialize()+"&type="+'WMI'+"&propId="+probe[num].id, //传的参数
				dataType : 'json',
				success : function(data) { //结果
					var obj= document.getElementById("result");
					if(data.flag == "true"){
						obj.options[num].text = "通过	"+probe[num].name+"	与	"+data.ip+"	连接成功！";
					}else{
						obj.options[num].text = "通过	"+probe[num].name+"	与	"+data.ip+"	连接失败！";
					}
					num++;
					if(num < probe.length){
						connTest(probe,num);
					}
				}
		});
  }
  
  </script>
  </head>
  
  <body class="padding-8">
    	<form action="" id="myform" name="myform" method="post">
    		<table class="table_eidt">
    			<tr>
	    			<td class="td_left" width="80px"><span class="span_alert">*</span>主机IP</td>
	    			<td class="td_right">${protocolParameter.ip}
	    			<span id="ipTip" style="width:150px"></span></td>
    			</tr>
    			<!-- 
    			<tr>
	    			<td class="td_left">负责人</td>
	    			<td class="td_right" colspan="2" >
		      	   		<select id="administrator" name="administrator" multiple="multiple" size="1"  class="select" style="width:425px;text-align:center;" >
		      	   		</select>
	    			</td>
    			</tr>
    			 -->
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>帐号</td>
	    			<td class="td_right"><input type="text" name="userName" id="userName" value="${protocolParameter.userName}" class="input_text">
	    			<span id="userNameTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left">密码</td>
	    			<td class="td_right"><input type="password" name="pwd" id="pwd" class="input_text">
	    			<span id="pwdTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left">确认密码</td>
	    			<td class="td_right"><input type="password" name="pwd1" id="pwd1" class="input_text">
	    			<span id="pwd1Tip" style="width:150px"></span></td>
    			</tr>
    		</table>
    		<div align="center" style="margin-top:9px;">
    		<input type="button" id="connTest" name="connTest" value="测试" class="btn-4" onclick="test();">
	    		<input type="submit" id="button" name="button" value="保存" class="btn-4">
	    		<input type="reset" class="btn-4">
	    		<input type="button" value="取消" onclick="closewin();" class="btn-4">
    		</div>
    		<input type="hidden" name="id" id="id" value="${protocolParameter.id}" >
    		<input type="hidden" name="ip" id="ip" value="${protocolParameter.ip}" >
    		<table class="table_eidt" style="margin-top:9px;display: none;" id="testTable">
    			<tr>
	    			<td class="td_left" width="80px">测试结果</td>
	    			<td class="td_right">
	    				<div><select multiple="multiple" id="result" style="width:390px; height: 40px;border-style:solid; border-width:1px; border-color:#cccccc;overflow: auto;"></select></div>
	    			</td>
    			</tr>
    		</table>
    	</form>
  </body>
</html>
